package ZombieCaminando;

import java.util.ArrayList;

import java.util.Iterator;

public class Juego  implements Runnable {

        protected ArrayList<Zombie> Zombies;
        protected Thread HiloJuego;
        protected Ventana ventana;
       
        public Juego(Ventana vent) {             
                Zombies = new ArrayList<Zombie>();
                ventana =vent;
                inicializarEntidades();
                (new Thread(this)).start();
               
        }



        private void inicializarEntidades() {
               
                Zombies.add(new Zombi((ventana.getHeight()/2),ventana.getWidth()/2, this));
                for (Zombie z:Zombies)
                {
                	z.start();
                }
        }




        private void juegoFinalizado() {
        	
        }



        public void run() {
                try {
                	boolean aux = true;
                	while(aux)
                	if(perdio()){
                		aux=false;
                		ventana.perdio();}
                } catch (Exception e) {
                       
                }
        }
        
        public Ventana getVentana(){
        	return ventana;
        }
        
        public boolean perdio(){
        	Iterator<Zombie> it = Zombies.iterator();
        	Zombie z;
        	int pos;
        	boolean salida = false;
            while(it.hasNext() && !salida){
            	z = it.next();
            	pos= z.getX();
            	if(pos <= 0)
            		salida = true;}
            return salida;     	
            	
            }


        private void reiniciarJuego() {

        }
}

